'use strict';

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var util = require('util');
var format = require('date-format');

function BaseSchema() {
    Schema.apply(this, arguments);
    this.add({
        createdAt: {type: Date, default: Date.now}, // 创建时间
        updatedAt: {type: Date, default: Date.now}  // 更新时间
    });

    //
    this.virtual('createTime').get(function () {
        return format('yyyy-MM-dd hh:mm:ss', this.createdAt);
    });
    this.virtual('updateTime').get(function () {
        return format('yyyy-MM-dd hh:mm:ss', this.updatedAt);
    });
}
util.inherits(BaseSchema, Schema);
module.exports = BaseSchema;
